Load packages.
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggmap)
## ℹ Google's Terms of Service: <https://mapsplatform.google.com>
## Stadia Maps' Terms of Service: <https://stadiamaps.com/terms-of-service/>
## OpenStreetMap's Tile Usage Policy: <https://operations.osmfoundation.org/policies/tiles/>
## ℹ Please cite ggmap if you use it! Use `citation("ggmap")` for details.
library(geosphere)
library(lubridate)
library(plotly)
##
## Attaching package: 'plotly'
##
## The following object is masked from 'package:ggmap':
##
## wind
##
## The following object is masked from 'package:ggplot2':
##
## last_plot
##
## The following object is masked from 'package:stats':
##
## filter
##
## The following object is masked from 'package:graphics':
##
## layout
Elk data from Wayne.
elk = read_csv("./data/elk.csv")
## Rows: 104913 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (7): elk_id, year, month, day, hour, lat, long
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
all_data csv from Wayne.
all_data <- read_csv("./data/all_data.csv")
## Rows: 104913 Columns: 16
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## dbl (15): elk_id, year, month, day, hour, lat, long, dist_km, land_cover, t...
## dttm (1): dt
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Load and clean up weather data.
raw_weather <- read_csv("./data/raw_weather_data.csv")
## Warning: One or more parsing issues, call `problems()` on your data frame for details,
## e.g.:
## dat <- vroom(...)
## problems(dat)
## Rows: 54745 Columns: 31
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): STATION, NAME
## dbl (21): LATITUDE, LONGITUDE, ELEVATION, AWND, DAPR, MDPR, PRCP, SNOW, SNW...
## lgl (7): MDSF, WT02, WT03, WT04, WT05, WT06, WT11
## date (1): DATE
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Plot weather stations and elk migration pathways to determine which stations to use.
weather_stations <-
raw_weather |>
group_by(NAME, LATITUDE, LONGITUDE) |>
summarize(n_obs = n())
## `summarise()` has grouped output by 'NAME', 'LATITUDE'. You can override using
## the `.groups` argument.
ggplot() +
geom_path(
data = elk,
aes(x=long, y=lat),
alpha = 0.5,
color = "red") +
geom_point(data = weather_stations, aes(x = LONGITUDE, y = LATITUDE))
ggplot(data = weather_stations,
aes(x = LONGITUDE, y = LATITUDE)) +
geom_point() +
ggrepel::geom_label_repel(aes(label = NAME),
box.padding = 0.35,
point.padding = 0.5,
segment.color = 'grey50',
max.overlaps = 20)
potential_stations <-
c("LEWIS LAKE DIVIDE, WY US", "SNAKE RIVER, WY US", "SNAKE RIVER STATION, WY US", "BASE CAMP, WY US",
"MORAN 5 WNW, WY US", "JACKSON 29.9 NNE, WY US", "BURRO HILL WYOMING, WY US", "MOOSE 1 NNE, WY US",
"MOOSE, WY US", "MOOSE .4 S, WY US", "JACKSON 12.3 NE, WY US", "JACKSON 12.2 NE, WY US",
"JACKSON HOLE AIRPORT, WY US", "JACKSON, WY US")
four_stations <-
c("SNAKE RIVER STATION, WY US", "MORAN 5 WNW, WY US", "BURRO HILL WYOMING, WY US", "MOOSE 1 NNE, WY US")
reduced_weather_stations <-
raw_weather |>
filter(NAME %in% four_stations) |>
group_by(NAME, LATITUDE, LONGITUDE) |>
summarize(n_obs = n()) |>
arrange(desc(n_obs))
## `summarise()` has grouped output by 'NAME', 'LATITUDE'. You can override using
## the `.groups` argument.
four_stations_labels_plot <-
ggplot(data = reduced_weather_stations,
aes(x = LONGITUDE, y = LATITUDE)) +
geom_point() +
ggrepel::geom_label_repel(aes(label = NAME),
box.padding = 0.35,
point.padding = 0.5,
segment.color = 'grey50',
max.overlaps = 20)
four_stations_labels_plot
four_stations_elk_mvmt_plot <-
ggplot() +
geom_path(
data = elk,
aes(x=long, y=lat),
alpha = 0.5,
color = "red") +
geom_point(data = reduced_weather_stations, aes(x = LONGITUDE, y = LATITUDE))
four_stations_elk_mvmt_plot
Reduce weather station data, explore weather data.
reduced_weather <-
raw_weather |>
filter(NAME %in% four_stations)
What kinds of monthly weather patterns were visible over this time period?
Find patterns in temp, rainfall, snowfall over time. Factor by month. Avg rainfall total, snowfall total, snow depth total, temp avg.
Total precip – avg totals among the four stations. Three ways to show data: faceted bar chart per year, point + line graph per year, year-month bar chart separated by year
# faceted bar chart, separated by month and year
reduced_weather |>
select(c(STATION, NAME, LATITUDE, LONGITUDE, DATE, PRCP, SNOW, SNWD, TAVG)) |>
mutate(year = format(DATE, "%Y"),
month = format(DATE, "%m")) |>
group_by(NAME, year, month) |>
summarize(station_precip_total = sum(PRCP, na.rm = TRUE)) |>
group_by(year, month) |>
summarize(station_precip_total_avg = mean(station_precip_total, na.rm = TRUE)) |>
mutate(year_month = paste(year, month, sep = "-")) |>
ggplot(aes(x = month, y = station_precip_total_avg, fill = as.factor(year))) +
geom_bar(stat = "identity") +
facet_wrap(vars(year), ncol = 2) +
theme(legend.position = "none") +
labs(x = "Month", y = "Total Precipitation (in)")
## `summarise()` has grouped output by 'NAME', 'year'. You can override using the
## `.groups` argument.
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
# point + line, separated by month and year
reduced_weather |>
select(c(STATION, NAME, LATITUDE, LONGITUDE, DATE, PRCP, SNOW, SNWD, TAVG)) |>
mutate(year = format(DATE, "%Y"),
month = format(DATE, "%m")) |>
group_by(NAME, year, month) |>
summarize(station_precip_total = sum(PRCP, na.rm = TRUE)) |>
group_by(year, month) |>
summarize(station_precip_total_avg = mean(station_precip_total, na.rm = TRUE)) |>
mutate(year_month = paste(year, month, sep = "-")) |>
ggplot(aes(x = month, y = station_precip_total_avg, color = year, group = year)) +
geom_point(size = 2) +
geom_line(linewidth = 1) +
labs(x = "Month", y = "Total Precipitation (in)", color = "Year")
## `summarise()` has grouped output by 'NAME', 'year'. You can override using the
## `.groups` argument.
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
# year-month totals, separated by year
reduced_weather |>
select(c(STATION, NAME, LATITUDE, LONGITUDE, DATE, PRCP, SNOW, SNWD, TAVG)) |>
mutate(year = format(DATE, "%Y"),
month = format(DATE, "%m")) |>
group_by(NAME, year, month) |>
summarize(station_precip_total = sum(PRCP, na.rm = TRUE)) |>
group_by(year, month) |>
summarize(station_precip_total_avg = mean(station_precip_total, na.rm = TRUE)) |>
mutate(year_month = paste(year, month, sep = "-")) |>
ggplot(aes(x = year_month, y = station_precip_total_avg, fill = as.factor(year))) +
geom_bar(stat = "identity") +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
labs(x = "Date (Year, Month)", y = "Total Precipitation (in)", fill = "Year")
## `summarise()` has grouped output by 'NAME', 'year'. You can override using the
## `.groups` argument.
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
Precip plotly.
# point + line, separated by month and year
reduced_weather |>
select(c(STATION, NAME, LATITUDE, LONGITUDE, DATE, PRCP, SNOW, SNWD, TAVG)) |>
mutate(year = format(DATE, "%Y"),
month = format(DATE, "%m")) |>
group_by(NAME, year, month) |>
summarize(station_precip_total = sum(PRCP, na.rm = TRUE)) |>
group_by(year, month) |>
summarize(station_precip_total_avg = mean(station_precip_total, na.rm = TRUE)) |>
mutate(year_month = paste(year, month, sep = "-")) |>
plot_ly(
x = ~month, y = ~station_precip_total_avg, color = ~year, group = ~year, type = 'scatter', mode = 'lines'
) |>
layout(xaxis = list(title = "Month"),
yaxis = list(title = "Total Precipitation (in)"), legend = list(title = list(text = "Year")))
## `summarise()` has grouped output by 'NAME', 'year'. You can override using the
## `.groups` argument.
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
## Warning in plot_ly(mutate(summarize(group_by(summarize(group_by(mutate(select(reduced_weather, : The group argument has been deprecated. Use `group_by()` or split instead.
## See `help('plotly_data')` for examples
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
# year-month totals, separated by year
reduced_weather |>
select(c(STATION, NAME, LATITUDE, LONGITUDE, DATE, PRCP, SNOW, SNWD, TAVG)) |>
mutate(year = format(DATE, "%Y"),
month = format(DATE, "%m")) |>
group_by(NAME, year, month) |>
summarize(station_precip_total = sum(PRCP, na.rm = TRUE)) |>
group_by(year, month) |>
summarize(station_precip_total_avg = mean(station_precip_total, na.rm = TRUE)) |>
mutate(year_month = paste(year, month, sep = "-")) |>
plot_ly(
x = ~year_month, y = ~station_precip_total_avg, color = ~as.factor(year), type = "bar"
) |>
layout(xaxis = list(title = "Date (Year, Month)"),
yaxis = list(title = "Total Precipitation (in)"), legend = list(title = list(text = "Year")))
## `summarise()` has grouped output by 'NAME', 'year'. You can override using the
## `.groups` argument.
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
Snowfall.
# faceted bar chart, separated by month and year -- KEEP STATIC, USE FOR ANALYSIS PAGE
reduced_weather |>
select(c(STATION, NAME, LATITUDE, LONGITUDE, DATE, PRCP, SNOW, SNWD, TAVG)) |>
mutate(year = format(DATE, "%Y"),
month = format(DATE, "%m")) |>
group_by(NAME, year, month) |>
summarize(station_snowfall_total = sum(SNOW, na.rm = TRUE)) |>
group_by(year, month) |>
summarize(station_snowfall_total_avg = mean(station_snowfall_total, na.rm = TRUE)) |>
mutate(year_month = paste(year, month, sep = "-")) |>
ggplot(aes(x = month, y = station_snowfall_total_avg, fill = as.factor(year))) +
geom_bar(stat = "identity") +
facet_wrap(vars(year), ncol = 2) +
theme(legend.position = "none") +
labs(x = "Month", y = "Total Snowfall (in)")
## `summarise()` has grouped output by 'NAME', 'year'. You can override using the
## `.groups` argument.
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
# point + line -- MAKE DYNAMIC, USE FOR DASHBOARD
reduced_weather |>
select(c(STATION, NAME, LATITUDE, LONGITUDE, DATE, PRCP, SNOW, SNWD, TAVG)) |>
mutate(year = format(DATE, "%Y"),
month = format(DATE, "%m")) |>
group_by(NAME, year, month) |>
summarize(station_snowfall_total = sum(SNOW, na.rm = TRUE)) |>
group_by(year, month) |>
summarize(station_snowfall_total_avg = mean(station_snowfall_total, na.rm = TRUE)) |>
mutate(year_month = paste(year, month, sep = "-")) |>
ggplot(aes(x = month, y = station_snowfall_total_avg, color = year, group = year)) +
geom_point(size = 2) +
geom_line(linewidth = 1) +
labs(x = "Month", y = "Total Snowfall (in)", color = "Year")
## `summarise()` has grouped output by 'NAME', 'year'. You can override using the
## `.groups` argument.
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
# year-month totals by year -- MAKE DYNAMIC, USE FOR DASHBOARD
reduced_weather |>
select(c(STATION, NAME, LATITUDE, LONGITUDE, DATE, PRCP, SNOW, SNWD, TAVG)) |>
mutate(year = format(DATE, "%Y"),
month = format(DATE, "%m")) |>
group_by(NAME, year, month) |>
summarize(station_snowfall_total = sum(SNOW, na.rm = TRUE)) |>
group_by(year, month) |>
summarize(station_snowfall_total_avg = mean(station_snowfall_total, na.rm = TRUE)) |>
mutate(year_month = paste(year, month, sep = "-")) |>
ggplot(aes(x = year_month, y = station_snowfall_total_avg, fill = as.factor(year))) +
geom_bar(stat = "identity") +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
labs(x = "Date (Year, Month)", y = "Total Snowfall (in)", fill = "Year")
## `summarise()` has grouped output by 'NAME', 'year'. You can override using the
## `.groups` argument.
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
Snowfall plotly.
# point + line
reduced_weather |>
select(c(STATION, NAME, LATITUDE, LONGITUDE, DATE, PRCP, SNOW, SNWD, TAVG)) |>
mutate(year = format(DATE, "%Y"),
month = format(DATE, "%m")) |>
group_by(NAME, year, month) |>
summarize(station_snowfall_total = sum(SNOW, na.rm = TRUE)) |>
group_by(year, month) |>
summarize(station_snowfall_total_avg = mean(station_snowfall_total, na.rm = TRUE)) |>
mutate(year_month = paste(year, month, sep = "-")) |>
plot_ly(
x = ~month, y = ~station_snowfall_total_avg, color = ~as.factor(year), group = ~year, type = 'scatter', mode = 'lines'
) |>
layout(xaxis = list(title = "Month"),
yaxis = list(title = "Total Snowfall (in)"), legend = list(title = list(text = "Year")))
## `summarise()` has grouped output by 'NAME', 'year'. You can override using the
## `.groups` argument.
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
## Warning in plot_ly(mutate(summarize(group_by(summarize(group_by(mutate(select(reduced_weather, : The group argument has been deprecated. Use `group_by()` or split instead.
## See `help('plotly_data')` for examples
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
# year-month totals by year
reduced_weather |>
select(c(STATION, NAME, LATITUDE, LONGITUDE, DATE, PRCP, SNOW, SNWD, TAVG)) |>
mutate(year = format(DATE, "%Y"),
month = format(DATE, "%m")) |>
group_by(NAME, year, month) |>
summarize(station_snowfall_total = sum(SNOW, na.rm = TRUE)) |>
group_by(year, month) |>
summarize(station_snowfall_total_avg = mean(station_snowfall_total, na.rm = TRUE)) |>
mutate(year_month = paste(year, month, sep = "-")) |>
plot_ly(
x = ~year_month, y = ~station_snowfall_total_avg, color = ~year, type = 'bar'
) |>
layout(xaxis = list(title = "Date (Year, Month)"),
yaxis = list(title = "Total Snowfall (in)"), legend = list(title = list(text = "Year")))
## `summarise()` has grouped output by 'NAME', 'year'. You can override using the
## `.groups` argument.
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
Snow depth.
# faceted bar chart, separated by month and year -- KEEP STATIC, USE FOR ANALYSIS PAGE
reduced_weather |>
select(c(STATION, NAME, LATITUDE, LONGITUDE, DATE, PRCP, SNOW, SNWD, TAVG)) |>
mutate(year = format(DATE, "%Y"),
month = format(DATE, "%m")) |>
group_by(NAME, year, month) |>
summarize(station_snowdepth_total = sum(SNWD, na.rm = TRUE)) |>
group_by(year, month) |>
summarize(station_snowdepth_total_avg = mean(station_snowdepth_total, na.rm = TRUE)) |>
mutate(year_month = paste(year, month, sep = "-")) |>
ggplot(aes(x = month, y = station_snowdepth_total_avg, fill = as.factor(year))) +
geom_bar(stat = "identity") +
facet_wrap(vars(year), ncol = 2) +
theme(legend.position = "none") +
labs(x = "Month", y = "Total Snow Depth (in)")
## `summarise()` has grouped output by 'NAME', 'year'. You can override using the
## `.groups` argument.
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
# point + line -- MAKE DYNAMIC, USE FOR DASHBOARD
reduced_weather |>
select(c(STATION, NAME, LATITUDE, LONGITUDE, DATE, PRCP, SNOW, SNWD, TAVG)) |>
mutate(year = format(DATE, "%Y"),
month = format(DATE, "%m")) |>
group_by(NAME, year, month) |>
summarize(station_snowdepth_total = sum(SNWD, na.rm = TRUE)) |>
group_by(year, month) |>
summarize(station_snowdepth_total_avg = mean(station_snowdepth_total, na.rm = TRUE)) |>
mutate(year_month = paste(year, month, sep = "-")) |>
ggplot(aes(x = month, y = station_snowdepth_total_avg, color = year, group = year)) +
geom_point(size = 2) +
geom_line(linewidth = 1) +
labs(x = "Month", y = "Total Snow Depth (in)", color = "Year")
## `summarise()` has grouped output by 'NAME', 'year'. You can override using the
## `.groups` argument.
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
# year-month totals -- MAKE DYNAMIC, USE FOR DASHBOARD
reduced_weather |>
select(c(STATION, NAME, LATITUDE, LONGITUDE, DATE, PRCP, SNOW, SNWD, TAVG)) |>
mutate(year = format(DATE, "%Y"),
month = format(DATE, "%m")) |>
group_by(NAME, year, month) |>
summarize(station_snowdepth_total = sum(SNWD, na.rm = TRUE)) |>
group_by(year, month) |>
summarize(station_snowdepth_total_avg = mean(station_snowdepth_total, na.rm = TRUE)) |>
mutate(year_month = paste(year, month, sep = "-")) |>
ggplot(aes(x = year_month, y = station_snowdepth_total_avg, fill = as.factor(year))) +
geom_bar(stat = "identity") +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
labs(x = "Date (Year, Month)", y = "Total Snow Depth (in)", fill = "Year")
## `summarise()` has grouped output by 'NAME', 'year'. You can override using the
## `.groups` argument.
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
Snow depth plotly.
# point + line
reduced_weather |>
select(c(STATION, NAME, LATITUDE, LONGITUDE, DATE, PRCP, SNOW, SNWD, TAVG)) |>
mutate(year = format(DATE, "%Y"),
month = format(DATE, "%m")) |>
group_by(NAME, year, month) |>
summarize(station_snowdepth_total = sum(SNWD, na.rm = TRUE)) |>
group_by(year, month) |>
summarize(station_snowdepth_total_avg = mean(station_snowdepth_total, na.rm = TRUE)) |>
mutate(year_month = paste(year, month, sep = "-")) |>
plot_ly(
x = ~month, y = ~station_snowdepth_total_avg, color = ~as.factor(year), group = ~year, type = 'scatter', mode = 'lines'
) |>
layout(xaxis = list(title = "Month"),
yaxis = list(title = "Total Snow Depth (in)"), legend = list(title = list(text = "Year")))
## `summarise()` has grouped output by 'NAME', 'year'. You can override using the
## `.groups` argument.
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
## Warning in plot_ly(mutate(summarize(group_by(summarize(group_by(mutate(select(reduced_weather, : The group argument has been deprecated. Use `group_by()` or split instead.
## See `help('plotly_data')` for examples
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
# year-month totals
reduced_weather |>
select(c(STATION, NAME, LATITUDE, LONGITUDE, DATE, PRCP, SNOW, SNWD, TAVG)) |>
mutate(year = format(DATE, "%Y"),
month = format(DATE, "%m")) |>
group_by(NAME, year, month) |>
summarize(station_snowdepth_total = sum(SNWD, na.rm = TRUE)) |>
group_by(year, month) |>
summarize(station_snowdepth_total_avg = mean(station_snowdepth_total, na.rm = TRUE)) |>
mutate(year_month = paste(year, month, sep = "-")) |>
plot_ly(
x = ~year_month, y = ~station_snowdepth_total_avg, color = ~year, type = 'bar'
) |>
layout(xaxis = list(title = "Date (Year, Month)"),
yaxis = list(title = "Total Snow Depth (in)"), legend = list(title = list(text = "Year")))
## `summarise()` has grouped output by 'NAME', 'year'. You can override using the
## `.groups` argument.
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
Avg temp.
# faceted bar chart, separated by month and year -- KEEP STATIC, USE FOR ANALYSIS PAGE
reduced_weather |>
select(c(STATION, NAME, LATITUDE, LONGITUDE, DATE, PRCP, SNOW, SNWD, TAVG)) |>
mutate(year = format(DATE, "%Y"),
month = format(DATE, "%m")) |>
group_by(year, month) |>
summarize(year_month_tavg = mean(TAVG, na.rm = TRUE)) |>
mutate(year_month = paste(year, month, sep = "-")) |>
ggplot(aes(x = month, y = year_month_tavg, fill = as.factor(year))) +
geom_bar(stat = "identity") +
facet_wrap(vars(year), ncol = 2) +
theme(legend.position = "none") +
labs(x = "Month", y = "Average Temperature (F)")
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
# point + line -- MAKE DYNAMIC, USE FOR DASHBOARD
reduced_weather |>
select(c(STATION, NAME, LATITUDE, LONGITUDE, DATE, PRCP, SNOW, SNWD, TAVG)) |>
mutate(year = format(DATE, "%Y"),
month = format(DATE, "%m")) |>
group_by(year, month) |>
summarize(year_month_tavg = mean(TAVG, na.rm = TRUE)) |>
mutate(year_month = paste(year, month, sep = "-")) |>
ggplot(aes(x = month, y = year_month_tavg, color = year, group = year)) +
geom_point(size = 2) +
geom_line(linewidth = 1) +
labs(x = "Month", y = "Average Temperature (F)", color = "Year")
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
# year-month totals -- MAKE DYNAMIC, USE FOR DASHBOARD
reduced_weather |>
select(c(STATION, NAME, LATITUDE, LONGITUDE, DATE, PRCP, SNOW, SNWD, TAVG)) |>
mutate(year = format(DATE, "%Y"),
month = format(DATE, "%m")) |>
group_by(year, month) |>
summarize(year_month_tavg = mean(TAVG, na.rm = TRUE)) |>
mutate(year_month = paste(year, month, sep = "-")) |>
ggplot(aes(x = year_month, y = year_month_tavg, fill = as.factor(year))) +
geom_bar(stat = "identity") +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
labs(x = "Date (Year, Month)", y = "Average Temperature (F)", fill = "Year")
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
Avg temp plotly.
# point + line
reduced_weather |>
select(c(STATION, NAME, LATITUDE, LONGITUDE, DATE, PRCP, SNOW, SNWD, TAVG)) |>
mutate(year = format(DATE, "%Y"),
month = format(DATE, "%m")) |>
group_by(year, month) |>
summarize(year_month_tavg = mean(TAVG, na.rm = TRUE)) |>
mutate(year_month = paste(year, month, sep = "-")) |>
plot_ly(
x = ~month, y = ~year_month_tavg, color = ~as.factor(year), group = ~year, type = 'scatter', mode = 'lines'
) |>
layout(xaxis = list(title = "Month"),
yaxis = list(title = "Average Temperature (F)"), legend = list(title = list(text = "Year")))
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
## Warning in plot_ly(mutate(summarize(group_by(mutate(select(reduced_weather, : The group argument has been deprecated. Use `group_by()` or split instead.
## See `help('plotly_data')` for examples
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
# year-month totals
reduced_weather |>
select(c(STATION, NAME, LATITUDE, LONGITUDE, DATE, PRCP, SNOW, SNWD, TAVG)) |>
mutate(year = format(DATE, "%Y"),
month = format(DATE, "%m")) |>
group_by(year, month) |>
summarize(year_month_tavg = mean(TAVG, na.rm = TRUE)) |>
mutate(year_month = paste(year, month, sep = "-")) |>
plot_ly(
x = ~year_month, y = ~year_month_tavg, color = ~year, type = 'bar'
) |>
layout(xaxis = list(title = "Date (Year, Month)"),
yaxis = list(title = "Average Temperature (F)"), legend = list(title = list(text = "Year")))
## `summarise()` has grouped output by 'year'. You can override using the
## `.groups` argument.
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(N, "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
Scatterplot of daily elk movement versus precip Scatterplot of daily elk movement versus snowfall Scatterplot of daily elk movement versus snow depth Scatterplot of daily elk movement versus temperature
Daily elk.
daily_elk <-
all_data |>
mutate(year_month_day = format(dt, "%Y-%m-%d"),
elk_id = as.character(elk_id)) |>
group_by(
elk_id,
year_month_day,
year,
month,
day,
tavg,
prcp,
snow,
snwd,
tmin,
tmax
) |>
summarize(
dist_km = sum(dist_km, na.rm = TRUE),
land_cover = mean(land_cover, na.rm = TRUE)
)
## `summarise()` has grouped output by 'elk_id', 'year_month_day', 'year',
## 'month', 'day', 'tavg', 'prcp', 'snow', 'snwd', 'tmin'. You can override using
## the `.groups` argument.
FOR ALL OF THE PLOTS BELOW, MAKE STATIC AND DYNAMIC, AND USE ON BOTH ANALYSIS PAGE AND DASHBOARD
Elk mvmt vs precip.
elk_prcp_distkm_pts <-
daily_elk |>
ggplot(aes(x = prcp, y = dist_km)) +
geom_point() +
geom_smooth(se = FALSE) +
labs(x = "Daily Precipitation (in)", y = "Daily Distance Traveled (km)")
style(elk_prcp_distkm_pts, hoverinfo = "none", traces = 2)
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 143 rows containing non-finite outside the scale range
## (`stat_smooth()`).
elk_prcp_distkm_smooth <-
daily_elk |>
ggplot(aes(x = prcp, y = dist_km, color = elk_id)) +
geom_smooth(se = FALSE) +
labs(x = "Daily Precipitation (in)", y = "Daily Distance Traveled (km)", color = "Elk ID")
ggplotly(elk_prcp_distkm_smooth)
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
## Warning: Removed 143 rows containing non-finite outside the scale range
## (`stat_smooth()`).
Elk mvmt vs. snowfall.
elk_snowfall_distkm_pts <-
daily_elk |>
ggplot(aes(x = snow, y = dist_km)) +
geom_point() +
geom_smooth(se = FALSE) +
labs(x = "Daily Snowfall (in)", y = "Daily Distance Traveled (km)")
style(elk_snowfall_distkm_pts, hoverinfo = "none", traces = 2)
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 1296 rows containing non-finite outside the scale range
## (`stat_smooth()`).
elk_snowfall_distkm_smooth <-
daily_elk |>
ggplot(aes(x = snow, y = dist_km, color = elk_id)) +
geom_smooth(se = FALSE) +
labs(x = "Daily Snowfall (in)", y = "Daily Distance Traveled (km)", color = "Elk ID")
ggplotly(elk_snowfall_distkm_smooth)
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
## Warning: Removed 1296 rows containing non-finite outside the scale range
## (`stat_smooth()`).
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : at -0.0575
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : radius 0.0033063
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : all data on boundary of neighborhood. make span bigger
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : pseudoinverse used at -0.0575
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : neighborhood radius 0.0575
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : reciprocal condition number 1
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : zero-width neighborhood. make span bigger
## Warning: Failed to fit group 1.
## Caused by error in `predLoess()`:
## ! NA/NaN/Inf in foreign function call (arg 5)
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : at -0.0575
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : radius 0.0033063
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : all data on boundary of neighborhood. make span bigger
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : pseudoinverse used at -0.0575
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : neighborhood radius 0.0575
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : reciprocal condition number 1
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : zero-width neighborhood. make span bigger
## Warning: Failed to fit group 2.
## Caused by error in `predLoess()`:
## ! NA/NaN/Inf in foreign function call (arg 5)
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : pseudoinverse used at -0.05
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : neighborhood radius 0.55
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : reciprocal condition number 2.0045e-30
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : There are other near singularities as well. 0.25
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : at -0.05
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : radius 0.0025
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : all data on boundary of neighborhood. make span bigger
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : pseudoinverse used at -0.05
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : neighborhood radius 0.05
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : reciprocal condition number 1
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : zero-width neighborhood. make span bigger
## Warning: Failed to fit group 4.
## Caused by error in `predLoess()`:
## ! NA/NaN/Inf in foreign function call (arg 5)
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : at -0.065
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : radius 0.004225
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : all data on boundary of neighborhood. make span bigger
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : pseudoinverse used at -0.065
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : neighborhood radius 0.065
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : reciprocal condition number 1
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : zero-width neighborhood. make span bigger
## Warning: Failed to fit group 7.
## Caused by error in `predLoess()`:
## ! NA/NaN/Inf in foreign function call (arg 5)
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : at -0.065
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : radius 0.004225
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : all data on boundary of neighborhood. make span bigger
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : pseudoinverse used at -0.065
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : neighborhood radius 0.065
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : reciprocal condition number 1
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : zero-width neighborhood. make span bigger
## Warning: Failed to fit group 8.
## Caused by error in `predLoess()`:
## ! NA/NaN/Inf in foreign function call (arg 5)
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : at -0.065
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : radius 0.004225
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : all data on boundary of neighborhood. make span bigger
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : pseudoinverse used at -0.065
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : neighborhood radius 0.065
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : reciprocal condition number 1
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : zero-width neighborhood. make span bigger
## Warning: Failed to fit group 9.
## Caused by error in `predLoess()`:
## ! NA/NaN/Inf in foreign function call (arg 5)
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : at -0.065
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : radius 0.004225
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : all data on boundary of neighborhood. make span bigger
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : pseudoinverse used at -0.065
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : neighborhood radius 0.065
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : reciprocal condition number 1
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : zero-width neighborhood. make span bigger
## Warning: Failed to fit group 10.
## Caused by error in `predLoess()`:
## ! NA/NaN/Inf in foreign function call (arg 5)
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : at -0.065
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : radius 0.004225
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : all data on boundary of neighborhood. make span bigger
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : pseudoinverse used at -0.065
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : neighborhood radius 0.065
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : reciprocal condition number 1
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : zero-width neighborhood. make span bigger
## Warning: Failed to fit group 11.
## Caused by error in `predLoess()`:
## ! NA/NaN/Inf in foreign function call (arg 5)
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : at -0.06
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : radius 0.0036
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : all data on boundary of neighborhood. make span bigger
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : pseudoinverse used at -0.06
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : neighborhood radius 0.06
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : reciprocal condition number 1
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : zero-width neighborhood. make span bigger
## Warning: Failed to fit group 12.
## Caused by error in `predLoess()`:
## ! NA/NaN/Inf in foreign function call (arg 5)
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : at -0.065
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : radius 0.004225
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : all data on boundary of neighborhood. make span bigger
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : pseudoinverse used at -0.065
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : neighborhood radius 0.065
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : reciprocal condition number 1
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : zero-width neighborhood. make span bigger
## Warning: Failed to fit group 13.
## Caused by error in `predLoess()`:
## ! NA/NaN/Inf in foreign function call (arg 5)
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : at -0.06
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : radius 0.0036
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : all data on boundary of neighborhood. make span bigger
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : pseudoinverse used at -0.06
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : neighborhood radius 0.06
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : reciprocal condition number 1
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : zero-width neighborhood. make span bigger
## Warning: Failed to fit group 14.
## Caused by error in `predLoess()`:
## ! NA/NaN/Inf in foreign function call (arg 5)
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : at -0.06
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : radius 0.0036
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : all data on boundary of neighborhood. make span bigger
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : pseudoinverse used at -0.06
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : neighborhood radius 0.06
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : reciprocal condition number 1
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : zero-width neighborhood. make span bigger
## Warning: Failed to fit group 15.
## Caused by error in `predLoess()`:
## ! NA/NaN/Inf in foreign function call (arg 5)
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : at -0.065
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : radius 0.004225
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : all data on boundary of neighborhood. make span bigger
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : pseudoinverse used at -0.065
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : neighborhood radius 0.065
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : reciprocal condition number 1
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : zero-width neighborhood. make span bigger
## Warning: Failed to fit group 16.
## Caused by error in `predLoess()`:
## ! NA/NaN/Inf in foreign function call (arg 5)
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : at -0.06
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : radius 0.0036
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : all data on boundary of neighborhood. make span bigger
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : pseudoinverse used at -0.06
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : neighborhood radius 0.06
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : reciprocal condition number 1
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : zero-width neighborhood. make span bigger
## Warning: Failed to fit group 17.
## Caused by error in `predLoess()`:
## ! NA/NaN/Inf in foreign function call (arg 5)
Elk mvmt vs. snow depth.
elk_snowdepth_distkm_pts <-
daily_elk |>
ggplot(aes(x = snwd, y = dist_km)) +
geom_point() +
geom_smooth(se = FALSE) +
labs(x = "Daily Snow Depth (in)", y = "Daily Distance Traveled (km)")
style(elk_snowdepth_distkm_pts, hoverinfo = "none", traces = 2)
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 185 rows containing non-finite outside the scale range
## (`stat_smooth()`).
elk_snowdepth_distkm_smooth <-
daily_elk |>
ggplot(aes(x = snwd, y = dist_km, color = elk_id)) +
geom_smooth(se = FALSE) +
labs(x = "Daily Snow Depth (in)", y = "Daily Distance Traveled (km)", color = "Elk ID")
ggplotly(elk_snowdepth_distkm_smooth)
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
## Warning: Removed 185 rows containing non-finite outside the scale range
## (`stat_smooth()`).
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : pseudoinverse used at -0.16
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : neighborhood radius 1.16
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : reciprocal condition number 0
## Warning in simpleLoess(y, x, w, span, degree = degree, parametric = parametric,
## : There are other near singularities as well. 1
Elk mvmt vs avg temp.
elk_avgtemp_distkm_pts <-
daily_elk |>
ggplot(aes(x = tavg, y = dist_km)) +
geom_point() +
geom_smooth(se = FALSE) +
labs(x = "Average Daily Temperature (F)", y = "Daily Distance Traveled (km)")
style(elk_avgtemp_distkm_pts, hoverinfo = "none", traces = 2)
## `geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
## Warning: Removed 143 rows containing non-finite outside the scale range
## (`stat_smooth()`).
elk_avgtemp_distkm_smooth <-
daily_elk |>
ggplot(aes(x = tavg, y = dist_km, color = elk_id)) +
geom_smooth(se = FALSE) +
labs(x = "Average Daily Temperature (F)", y = "Daily Distance Traveled (km)", color = "Elk ID")
ggplotly(elk_avgtemp_distkm_smooth)
## `geom_smooth()` using method = 'loess' and formula = 'y ~ x'
## Warning: Removed 143 rows containing non-finite outside the scale range
## (`stat_smooth()`).